(function ({form, table, layer, laydate, SelectDatas, scoreinfoTableIns,scoreinfos,url, contentType, ok, AjaxFn, tablebtn, updataOpen, optionfor}) {


    SelectDatas = ((obj)=>(
        obj = AjaxFn(url + "appraisalSelectDatas", "", obj),
            {vappraisalsflg = '', vassessflg = ''} = obj,
            $("select[name=vassessflg]").html(optionfor(vassessflg, ``,"select")),
            $(".radioAppraisalsflg").html(optionfor(vappraisalsflg, "","radio"))
    ))({}),


    scoreinfoTableIns =  table.render({
        elem: '#scoreinfoTable',
        id:"scoreinfoTable",
        limit:6,
        page: {first: '首页', last: '尾页', prev: '上一页', next: '下一页', layout: ['count', 'prev', 'page', 'next'], groups: 5, theme: '#1e9fff', limits: [10, 20, 30, 40, 50],},
        cols: [
            [
                {title: '操作', fixed: "left", unresize: true, align: "center", width:80, minWidth: 80,
                    templet: function (d, updata = '') {
                        updata = tablebtn({"event": "del", "btnclass": "layui-btn layui-btn-xs layui-btn-danger", "icon": '&#xe640;', "text": '删除', "disabled": false})
                        return '<div>' + updata + '</div>';
                    }
                },
                {field: 'vstandard', title: '标准（答案）', unresize: true, align: "center", minWidth: 200},
                {field: 'iscore', title: '分值', unresize: true, align: "center", width:100,minWidth: 100},
            ]
        ],
        data: scoreinfos
    }),

    form.verify({
        costomnum :function(value){
            if (!/^[+-]{0,1}(\d+)$/.test(value)) return '不能输入小数';
        }
    }),

    form.render(),

    form.on('submit(scoreinfoAdd)',function ({field}) {
        field.vstandard = field.vstandard.trim()
        scoreinfos.length==0?(()=>(field.vno=1,scoreinfos.push(field)))(): scoreinfos.findIndex(v=>v.vstandard==field.vstandard)==-1?(()=>(field.vno=scoreinfos.length+1,scoreinfos.push(field)))():layer.msg('标准（答案）已存在', {icon: 7}),
        table.reload("scoreinfoTable",{data:scoreinfos}),
        form.val('scoreinfoForm',{vstandard:'', iscore:""});
        return false;
    }),

    form.on('submit(appraisalAdd)',function ({field,res=''}) {
        //scoreinfos.length==0?(layer.msg("必填项不能为空",{icon:5,anim: 6}),$("textarea[name=vstandard]").focus().addClass("layui-form-danger")):'';
        field.vcontent = field.vcontent.trim()
         scoreinfos.length==0?($("#scoreinfoAdd").click()):(
            res = AjaxFn(url+"appraisalAdd", JSON.stringify({field,scoreinfos}), {}),
            {code,msg}=res,code==200?(()=>(layer.alert(msg,{icon:1,skin: 'add-alert-class'},()=>window.location.reload())
            ))():layer.msg(msg,{icon:5})
        );

        return false;
    }),
    /*{data,event,tr}=obj*/
    table.on('tool(scoreinfoTable)',(obj)=>(obj.event=="del"?(() => (scoreinfos.splice(scoreinfos.findIndex(v=>v.vstandard==obj.data.vstandard),1),obj.del()))():''))


})({
    form: layui.form,
    table: layui.table,
    layer: layui.layer,
    laydate: layui.laydate,
    SelectDatas: {},
    scoreinfoTableIns:'',
    scoreinfos:[],
    url: "/evaluation/appraisal/",
    contentType: 'application/json;charset=utf-8',
    ok: function (msg, icon) {
        layui.layer.confirm(msg, {
            id: "ok",
            icon: icon,
            anim: 4,
            title: '提示',
            btn: ['确定'],
            closeBtn: false,
            success: function (layero) {
                var btn = layero[0].getElementsByClassName('layui-layer-btn')[0].getElementsByTagName('A')[0];
                btn.href = 'javascript:void(0)';
                btn.focus();
            },
            yes: function (index, layero) {
                layer.close(index); //再执行关闭
            },
            end: function () {
                var index2 = parent.layer.getFrameIndex(window.name);
                parent.layer.closeAll();
            }
        });
    },
    AjaxFn: function (url, data, resource) {
        $.ajax({
            url,
            contentType: 'application/json;charset=utf-8',
            type: 'post',
            async: false,
            data,
            success: function (res) {
                let {msg='',code=''} =res;
                msg=='' && code==''? top.location.reload() : "";
                resource = res;
            }
        });
        return resource;
    },
    tablebtn: function ({event = "", btnclass = "layui-btn btncolor ", icon = "", text = "", disabled = false, btn = ""}) {
        disabled ? disabled = "disabled" : disabled = '';
        btn = `<button type="button" ${disabled} class="${btnclass}" lay-event="${event}"><i class="layui-icon">${icon}</i>${text}</button>`
        return btn;
    },
    updataOpen: function ({url, skin, title, tableIns, btns = ['取消', '修改']}) {
        layer.open({
                anim: 4, type: 2, skin: skin, resize: false,
                title: [title, 'font-size:18px; background-color:#e7eaec;'],
                area: ['aotu'],
                btn: btns,
                content: url,
                btn2: function (index, layero) {
                    var body = layer.getChildFrame('body', index);
                    body.find('#submit').click();
                    return false;
                },
                end: function () {
                    tableIns.reload();
                }
            }
        ), $(`.${skin} iframe`).css('height', '100%'),
            $(".layui-layer-btn").css({
                "padding-top": "0px",
                "padding-bottom": "3px",
                "background-color": "rgb(231, 234, 236)"
            });
    },
    optionfor: (vappraisalsflg, op,rORs) => {
        rORs=="select"?
            (()=>(vappraisalsflg != '' ? $.each(vappraisalsflg, (i, item) => op += `<option value="${item.scode}">${item.vname}</option>`) : op = ""))():
        rORs=="radio"? (()=>(
                vappraisalsflg != '' ? $.each(vappraisalsflg, (i, item) =>(
                item.scode==0?rORs = "checked":rORs="",
                op += `<input type="radio" name="vappraisalsflg" ${rORs} value="${item.scode}" title="${item.vname}">`)) : op = ""
                )
            )():'';
        return op;
    },
})